using UnityEngine;
using UnityEngine.InputSystem;

public class Lesson3_Exercises : MonoBehaviour
{
    public GameObject obj = null;
    public Material redMaterial;
    private Material normalMaterial;
    float scale = 1;
    void Start()
    {
    }

    void Update()
    {
        if (Mouse.current.leftButton.wasPressedThisFrame)
        {
            RaycastHit info;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()), out info))
            {
                obj = info.collider.gameObject;
                normalMaterial = obj.GetComponent<MeshRenderer>().material;
                obj.GetComponent<MeshRenderer>().material = redMaterial;
            }
            else
            {
                if(obj != null)
                    obj.GetComponent<MeshRenderer>().material = normalMaterial;
                normalMaterial = null;
                obj = null;
            }
        }
        if (obj)
        {
            //+
            if (Keyboard.current.numpadPlusKey.wasPressedThisFrame || Keyboard.current.equalsKey.wasPressedThisFrame)
            {
                scale++;
                obj.transform.localScale = Vector3.one * scale;
                    Debug.LogFormat("+ scale:{0}", scale);
                }
            //-
            if (Keyboard.current.numpadMinusKey.wasPressedThisFrame || Keyboard.current.minusKey.wasPressedThisFrame)
            {
                scale--;
                if (scale < 1)
                    scale = 1;
                obj.transform.localScale = Vector3.one * scale;
                Debug.LogFormat("- scale:{0}", scale);
            }
        }
       
    }
}
